package com.jdbc_.datasource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

// 使用Druid连接的案例
public class Druid2 {
    public static void main(String[] args) throws SQLException {
        // 获取连接
        Connection connection = JDBCUtilsByDruid.getConnection();
        // 执行sql
        String sql = "select * from actor where id =?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, 1);
        ResultSet resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            System.out.println(id + "\t" + name);
        }

        // 关闭连接
        JDBCUtilsByDruid.close(resultSet, preparedStatement, connection);
    }
}
